/*
 * readconfig.h
 *
 *  Created on: 15/apr/2014
 *      Author: kappa
 */

#ifndef READCONFIG_H_
#define READCONFIG_H_

#include <stdio.h>
#include <stdlib.h>
#include "utils/ui.h"
#include "utils/errors.h"
#include "utils/commons.h"

#ifdef _WIN32
	#include <windows.h>
#else
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <fcntl.h>
	#include <unistd.h>
	#include <string.h>
	#include <ctype.h>
#endif

#ifdef _WIN32
#define CONFFILE "pkmailso.conf";
#define CONFDIR "config";
#else
#define CONFFILE "/etc/pkmailso.conf"
#endif

//Property di configurazione
#define STR_ISMULTH "isMultiThreaded"
#define STR_MXCONC "maxConcurrentPT"
#define STR_MXMSGLEN "maxMessageLength"
#define STR_SMTP_PORT "smtpPort"
#define STR_POP3_PORT "pop3Port"
#define STR_USR_CONF_PATH "usersConfPath"
#define STR_MAILBOX_PATH "mailboxPath"
#define STR_SECRETS_PATH "secretsFile"

#define MAX_PATH_LENGTH 256;
#define MAX_PROP_LENGTH 256;

//Configurazione Valori di default

#define IS_MULTI_THREAD_DEFAULT 1
#define MAX_CONC_DEFAULT 75
#define MAX_MSG_LEN_DEFAULT 2048
#define SMTP_PORT_DEFAULT 25
#define POP3_PORT_DEFAULT 110
#define SECRETS_PATH_DEFAULT "secrets.csv"

#ifdef _WIN32
#define USR_CONF_PATH_DEFAULT "config\\usr"
#define MAILBOX_PATH_DEFAULT  "mailboxes\\"
#else
#define USR_CONF_PATH_DEFAULT "config/usr"
#define MAILBOX_PATH_DEFAULT  "mailboxes/"
#endif

typedef struct ServerConfiguration{
	int isMultiThreaded;
	int maxConcurrentPT;
	int maxMessageLength;
	unsigned short int smtpPort;
	unsigned short int pop3Port;
	char *usersConfPath;
	char *mailboxPath;
	char *secretsFile;
}SRV_CNF;
typedef SRV_CNF *  CNF_PTR;

//void initConfiguration(CNF_PTR);
void initConfigObject(CNF_PTR);
void getConfiguration(CNF_PTR);
void getDefaultConfig(CNF_PTR*);
void printConfiguration(CNF_PTR);
char * prepareConfBuffer(CNF_PTR);
void writeDefaultConfig(void *,CNF_PTR );
void decodeConfigString(CNF_PTR *, char* );
void setProperty(CNF_PTR **, char *, int , char *);
#endif /* READCONFIG_H_ */


